% config.pro
%
% Initialise library search paths and file paths for kernels
%
% Specify the location of this file with an environment variable KERNEL_CONFIG
% e.g. KERNEL_CONFIG=/home/kernels/config.pro
%

:- dynamic
     user:prolog_file_type/2,
     user:file_search_path/2.
:- multifile
     user:prolog_file_type/2,
     user:file_search_path/2.

:- dynamic
     user:setting/1.


:- op( 450, xfx, (::) ).        % Expr::Type, explicit type annotation
%:- op( 675, xfx, (#) ).        % Expr::Type, explicit type annotation


:- dynamic
    user:(::)/2,
    user:(::)/4.     %2+2 for use in DCG

:-
    (setting(config_loaded)
        ->  true
        ;   (
                assert(setting(config_loaded)),

                % adopt .pro file extensions to avoid conflict with Perl .pl
                assert(user:prolog_file_type(pro, prolog)),

                % get path of this file (only succeeds on first load)
                prolog_load_context(directory, Sys),

                %
                % define module paths as kernel_xxxx()
                %
                (\+ user:file_search_path(kernel_sys, Sys)
                ->    asserta(user:file_search_path(kernel_sys, Sys))
                ),
                atom_concat(Sys, '/lib', Lib),
                (\+ user:file_search_path(kernel_lib, Lib)
                ->    asserta(user:file_search_path(kernel_lib, Lib))
                ),
                atom_concat(Sys, '/data', Data),
                (\+ user:file_search_path(kernel_data, Data)
                ->    asserta(user:file_search_path(kernel_data, Data))
                ),
                atom_concat(Sys, '/dcg', Dcg),
                (\+ user:file_search_path(kernel_dcg, Dcg)
                ->    asserta(user:file_search_path(kernel_dcg, Dcg))
                ),
                atom_concat(Sys, '/exp', Exp),
                (\+ user:file_search_path(kernel_exp, Exp)
                ->    asserta(user:file_search_path(kernel_exp, Exp))
                ),
                atom_concat(Sys, '/out', Out),
                (\+ user:file_search_path(kernel_out, Out)
                ->    asserta(user:file_search_path(kernel_out, Out))
                )
            )
    ).
